package com.yanyilu.jianjian.util;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;


public class PageUtil {

    public Integer pageSize(Integer page,Integer limit){
        Integer pagesize = (page-1)*limit;
        return pagesize;
    }

    public static Pageable pagelimit(Integer pageNum, Integer pageSize,String order){
        if(null==pageNum){
            pageNum = 1;
        }
        if(null == pageSize){
            pageSize = 5;
        }
        Sort sort = Sort.by(Sort.Direction.DESC, order);
        return PageRequest.of(pageNum - 1, pageSize, sort);
    }

    public static Pageable pagelimit(Integer pageNum, Integer pageSize){
        if(null==pageNum){
            pageNum = 1;
        }
        if(null == pageSize){
            pageSize = 10;
        }
        return  PageRequest.of(pageNum - 1, pageSize);
    }
}
